package com.tinem.platform.module.pojo.enums.message;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;

import java.util.HashMap;

/**
 * @author fengzhihao
 * @version v1
 * @program: platform
 * @className WebSocketMessageType
 * @description TODO
 * @site
 * @company
 * @create 2021/12/1 17:08:30
 */
@AllArgsConstructor
public enum MqttMessageType {
    //所有用户
    ALL_USER("{active}/platform/message/all_user/{clientId}")
    //单个用户
    ,USER("{active}/platform/message/user/{id}/")
    //单个用户
    ,GROUP("{active}/platform/message/group/{id}/")
    //用户上线
    ,USER_ONLINE("{active}/platform/message/user_online/{clientId}/")
    //用户下线
    ,USER_OFFLINE("{active}/platform/message/user_offline/{clientId}/")
    ;
    String topicName;

    public String getUserTopic(String active,String userId){
        return getTopicName(active,null,userId);
    }
    public String getGroupTopic(String active,String groupId){
        return getTopicName(active,null,groupId);
    }
    public String getTopic(String active,String clientId){
        return getTopicName(active,clientId,null);
    }
    private String getTopicName(String active,String clientId,String id){
        return StrUtil.format(this.topicName,new HashMap(){{
            put("active",active);
            put("clientId",clientId);
            put("id",id);
        }});
    }
}
